/**
 * @description: 防抖与节流
 */
export function throttleAndDebounce(fn, delay) {
  let timeout
  let called = false

  return (e) => {
    if (timeout)
      clearTimeout(timeout)

    if (!called) {
      fn(e)
      called = true
      setTimeout(() => {
        called = false
      }, delay)
    }
    else {
      timeout = setTimeout(() => {
        fn(e)
      }, delay)
    }
  }
}
